<?php

namespace app\common\validate;

use think\Validate;

class BaseValidate extends Validate
{
    protected $method = 'POST';

    public function get() {
        $this->method = "GET";
        return $this;
    }
    public function doCheck($scene = null)
    {
        if ($this->method === "POST") {
            $data = request()->post();
        } else {
            $data = request()->get();
        }
        if ($scene) {
            $result = $this->scene($scene)->failException(false)->check($data);
        } else {
            $result = $this->failException(false)->check($data);
        }

        if ($result !== true) {
            if (is_array($this->error)) {
                throwError(join(",",$this->error));
            } else {
                throwError($this->error);
            }
        }
        return $data;
    }
}